﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wpf树菜单项拖拽功能Demo2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        ObservableCollection<TreeItem> treeItemlist = new ObservableCollection<TreeItem>();
        public MainWindow()
        {
            InitializeComponent();
            initTree();
        }
        private void initTree()
        {
            var root1 = new TreeItem
            {
                TextName = "root1",
                Root = treeItemlist
            };
            var root2 = new TreeItem
            {
                TextName = "root2",
                Root = treeItemlist
            };
            var root3 = new TreeItem
            {
                TextName = "root3",
                Childern = new ObservableCollection<TreeItem> { 
                    new TreeItem { TextName = "root3_1", Root = treeItemlist },
                    new TreeItem { TextName = "root3_2", Root = treeItemlist }
                },
                Root = treeItemlist
            };

            foreach (var item in root3.Childern)
            {
                item.Parent = root3;
            }
            treeItemlist.Add(root1);
            treeItemlist.Add(root2);
            treeItemlist.Add(root3);
            treeView.ItemsSource = treeItemlist;
        }
    }
}
